﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace linkouqs.Gamekit
{

    public class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
    {

        public static T Instance
        {
            get
            {
                if (instacne == null)
                {
                    instacne = FindObjectOfType<T>();
                    if(instacne == null) {
                        throw new System.Exception("场景中找不到带 " + typeof(T).Name + "组件 的物体.");
                    }
                }
                return instacne;
            }
        }

        static T instacne;

        protected virtual void OnDestroy()
        {
            instacne = null;
        }

    }

}
